﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Terraria.DataStructures;

namespace Terraria.World.Generation
{
	// Token: 0x020000B9 RID: 185
	public class ShapeData
	{
		// Token: 0x170000C2 RID: 194
		// (get) Token: 0x06000A8A RID: 2698 RVA: 0x0000B4C4 File Offset: 0x000096C4
		public int Count
		{
			get
			{
				return this._points.Count;
			}
		}

		// Token: 0x06000A8B RID: 2699 RVA: 0x0000B4D1 File Offset: 0x000096D1
		public ShapeData()
		{
			this._points = new HashSet<Point16>();
		}

		// Token: 0x06000A8C RID: 2700 RVA: 0x0000B4E4 File Offset: 0x000096E4
		public ShapeData(ShapeData original)
		{
			this._points = new HashSet<Point16>(original._points);
		}

		// Token: 0x06000A8D RID: 2701 RVA: 0x0000B4FD File Offset: 0x000096FD
		public void Add(int x, int y)
		{
			this._points.Add(new Point16(x, y));
		}

		// Token: 0x06000A8E RID: 2702 RVA: 0x0000B512 File Offset: 0x00009712
		public void Remove(int x, int y)
		{
			this._points.Remove(new Point16(x, y));
		}

		// Token: 0x06000A8F RID: 2703 RVA: 0x0000B527 File Offset: 0x00009727
		public HashSet<Point16> GetData()
		{
			return this._points;
		}

		// Token: 0x06000A90 RID: 2704 RVA: 0x0000B52F File Offset: 0x0000972F
		public void Clear()
		{
			this._points.Clear();
		}

		// Token: 0x06000A91 RID: 2705 RVA: 0x0000B53C File Offset: 0x0000973C
		public bool Contains(int x, int y)
		{
			return this._points.Contains(new Point16(x, y));
		}

		// Token: 0x06000A92 RID: 2706 RVA: 0x003E650C File Offset: 0x003E470C
		public void Add(ShapeData shapeData, Point localOrigin, Point remoteOrigin)
		{
			foreach (Point16 point in shapeData.GetData())
			{
				this.Add(remoteOrigin.X - localOrigin.X + (int)point.X, remoteOrigin.Y - localOrigin.Y + (int)point.Y);
			}
		}

		// Token: 0x06000A93 RID: 2707 RVA: 0x003E6588 File Offset: 0x003E4788
		public void Subtract(ShapeData shapeData, Point localOrigin, Point remoteOrigin)
		{
			foreach (Point16 point in shapeData.GetData())
			{
				this.Remove(remoteOrigin.X - localOrigin.X + (int)point.X, remoteOrigin.Y - localOrigin.Y + (int)point.Y);
			}
		}

		// Token: 0x06000A94 RID: 2708 RVA: 0x003E6604 File Offset: 0x003E4804
		public static Rectangle GetBounds(Point origin, params ShapeData[] shapes)
		{
			int num = (int)shapes[0]._points.First<Point16>().X;
			int num2 = num;
			int num3 = (int)shapes[0]._points.First<Point16>().Y;
			int num4 = num3;
			for (int i = 0; i < shapes.Length; i++)
			{
				foreach (Point16 point in shapes[i]._points)
				{
					num = Math.Max(num, (int)point.X);
					num2 = Math.Min(num2, (int)point.X);
					num3 = Math.Max(num3, (int)point.Y);
					num4 = Math.Min(num4, (int)point.Y);
				}
			}
			return new Rectangle(num2 + origin.X, num4 + origin.Y, num - num2, num3 - num4);
		}

		// Token: 0x04000EEB RID: 3819
		private HashSet<Point16> _points;
	}
}
